package leetcode.每日一题;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zsy
 * @date ：Created 2022/10/15 8:52 PM
 * @description：https://leetcode.cn/problems/build-an-array-with-stack-operations/
 */
public class 用栈操作构建数组 {
    @Test
    public void test() {
        System.out.println(new Solution().buildArray(new int[]{1, 2}, 4));
    }

    class Solution {
        public List<String> buildArray(int[] target, int n) {
            List<String> list = new ArrayList<>();
            int j = 0;
            for (int i = 1; i <= n && j < target.length; i++) {
                if (target[j] == i) {
                    list.add("Push");
                    j++;
                } else {
                    list.add("Push");
                    list.add("Pop");
                }
            }
            return list;
        }
    }
}
